//
//  OrderDetailsArrayModel.swift
//  Pods
//
//  Created by eme on 2017/3/31.
//
//

import Foundation
import SwiftyJSON
import NetWorkCore
import ModelProtocol

class OrderDetailsArrayModel: ModelProtocol {
    
    // MARK: Declaration for string constants to be used to decode and also serialize.
    internal let kOrderDetailsArrayInvoiceflagKey: String = "invoiceflag"
    internal let kOrderDetailsArrayPdidKey: String = "pdid"
    internal let kOrderDetailsArrayPsfnameKey: String = "psfname"
    internal let kOrderDetailsArrayPayidKey: String = "payid"
    internal let kOrderDetailsArrayAdressKey: String = "adress"
    internal let kOrderDetailsArrayCommentKey: String = "comment"
    internal let kOrderDetailsArrayOrderstatusKey: String = "orderstatus"
    internal let kOrderDetailsArrayDetailidKey: String = "detailid"
    internal let kOrderDetailsArraySkuidKey: String = "skuid"
    internal let kOrderDetailsArrayImg1Key: String = "img1"
    internal let kOrderDetailsArrayIsshowKey: String = "isshow"
    internal let kOrderDetailsArrayOrderidKey: String = "orderid"
    internal let kOrderDetailsArrayDetailstatusKey: String = "detailstatus"
    internal let kOrderDetailsArrayPsfname2Key: String = "psfname2"
    internal let kOrderDetailsArrayBridKey: String = "brid"
    internal let kOrderDetailsArrayProvinceKey: String = "province"
    internal let kOrderDetailsArrayIsinvoiceKey: String = "isinvoice"
    internal let kOrderDetailsArraySendtypeKey: String = "sendtype"
    internal let kOrderDetailsArrayInvoicetitleKey: String = "invoicetitle"
    internal let kOrderDetailsArrayCityKey: String = "city"
    internal let kOrderDetailsArrayShpriceKey: String = "shprice"
    internal let kOrderDetailsArrayPdnameKey: String = "pdname"
    internal let kOrderDetailsArrayDetailrnumberKey: String = "detailrnumber"
    internal let kOrderDetailsArrayIsevaluateKey: String = "isevaluate"
    internal let kOrderDetailsArrayIssaleKey: String = "issale"
    internal let kOrderDetailsArrayUnderdateKey: String = "underdate"
    internal let kOrderDetailsArrayBdidKey: String = "bdid"
    internal let kOrderDetailsArraySpidKey: String = "spid"
    internal let kOrderDetailsArrayAreaKey: String = "area"
    internal let kOrderDetailsArrayCellphoneKey: String = "cellphone"
    internal let kOrderDetailsArrayPsvalueKey: String = "psvalue"
    internal let kOrderDetailsArrayInvoiceplaceKey: String = "invoiceplace"
    internal let kOrderDetailsArrayDetaildateKey: String = "detaildate"
    internal let kOrderDetailsArrayDetailtotalKey: String = "detailtotal"
    internal let kOrderDetailsArrayPostageKey: String = "postage"
    internal let kOrderDetailsArraySelfidKey: String = "selfid"
    internal let kOrderDetailsArrayRecipientsKey: String = "recipients"
    internal let kOrderDetailsArrayAgidKey: String = "agid"
    internal let kOrderDetailsArrayPsvalue2Key: String = "psvalue2"
    internal let kOrderDetailsArrayPdtypeKey: String = "pdtype"
    internal let kOrderDetailsArrayOrderamountKey: String = "orderamount"
    internal let kOrderDetailsArrayBdnameKey: String = "bdname"
    
    
    // MARK: 属性
    var invoiceflag: String
    var pdid: Int
    var psfname: String
    var payid: String
    var adress: String
    var comment: String
    var orderstatus: String
    var detailid: String
    var skuid: Int
    var img1: String
    var isshow: String
    var orderid: String
    var detailstatus: String
    var psfname2: String
    var brid: String
    var province: String
    var isinvoice: String
    var sendtype: String
    var invoicetitle: String
    var city: String
    var shprice: Double
    var pdname: String
    var detailrnumber: Int
    var isevaluate: String
    var issale: String
    var underdate: String
    var bdid: String
    var spid: String
    var area: String
    var cellphone: String
    var psvalue: String
    var invoiceplace: String
    var detaildate: String
    var detailtotal: Float
    var postage: Int
    var selfid: String
    var recipients: String
    var agid: String
    var psvalue2: String
    var pdtype: String
    var orderamount: Float
    var bdname: String
    var buttonArr = [UIButton]()
    var imageKeys = [String]()
    var statClicked = 0
    var leaveMessage:String = ""
    var standard:String{
        get{
            if psfname == ""
            {
                return ""
            }
            else if psfname2 == ""
            {
                if psvalue != ""{
                    return self.psfname + ":" + self.psvalue
                }else{
                    return self.psfname
                }
                
            }
            else
            {
                if self.psvalue != "" && psvalue2 != ""{
                    
                    return self.psfname + ":" + self.psvalue + ";" + self.psfname2 + ":" + self.psvalue2
                    
                }else if psvalue == "" && psvalue2 != ""{
                    
                    return self.psfname + ";" + self.psfname2 + ":" + self.psvalue2
                    
                }else if psvalue != "" && psvalue2 == ""{
                    
                    return self.psfname + ":" + self.psvalue + ";" + self.psfname2
                    
                }else{
                    return self.psfname + ";" + self.psfname2
                    
                }
            }
            
        }
        
    }
    
    // MARK: 实现MikerSwiftJSONAble 协议， 解析json数据
    required  init?(json: JSON) {
        invoiceflag = json[kOrderDetailsArrayInvoiceflagKey].stringValue
        pdid = json[kOrderDetailsArrayPdidKey].intValue
        psfname = json[kOrderDetailsArrayPsfnameKey].stringValue
        payid = json[kOrderDetailsArrayPayidKey].stringValue
        adress = json[kOrderDetailsArrayAdressKey].stringValue
        comment = json[kOrderDetailsArrayCommentKey].stringValue
        orderstatus = json[kOrderDetailsArrayOrderstatusKey].stringValue
        detailid = json[kOrderDetailsArrayDetailidKey].stringValue
        skuid = json[kOrderDetailsArraySkuidKey].intValue
        img1 = json[kOrderDetailsArrayImg1Key].stringValue
        isshow = json[kOrderDetailsArrayIsshowKey].stringValue
        orderid = json[kOrderDetailsArrayOrderidKey].stringValue
        detailstatus = json[kOrderDetailsArrayDetailstatusKey].stringValue
        psfname2 = json[kOrderDetailsArrayPsfname2Key].stringValue
        brid = json[kOrderDetailsArrayBridKey].stringValue
        province = json[kOrderDetailsArrayProvinceKey].stringValue
        isinvoice = json[kOrderDetailsArrayIsinvoiceKey].stringValue
        sendtype = json[kOrderDetailsArraySendtypeKey].stringValue
        invoicetitle = json[kOrderDetailsArrayInvoicetitleKey].stringValue
        city = json[kOrderDetailsArrayCityKey].stringValue
        shprice = json[kOrderDetailsArrayShpriceKey].doubleValue
        pdname = json[kOrderDetailsArrayPdnameKey].stringValue
        detailrnumber = json[kOrderDetailsArrayDetailrnumberKey].intValue
        isevaluate = json[kOrderDetailsArrayIsevaluateKey].stringValue
        issale = json[kOrderDetailsArrayIssaleKey].stringValue
        underdate = json[kOrderDetailsArrayUnderdateKey].stringValue
        bdid = json[kOrderDetailsArrayBdidKey].stringValue
        spid = json[kOrderDetailsArraySpidKey].stringValue
        area = json[kOrderDetailsArrayAreaKey].stringValue
        cellphone = json[kOrderDetailsArrayCellphoneKey].stringValue
        psvalue = json[kOrderDetailsArrayPsvalueKey].stringValue
        invoiceplace = json[kOrderDetailsArrayInvoiceplaceKey].stringValue
        detaildate = json[kOrderDetailsArrayDetaildateKey].stringValue
        detailtotal = json[kOrderDetailsArrayDetailtotalKey].floatValue
        postage = json[kOrderDetailsArrayPostageKey].intValue
        selfid = json[kOrderDetailsArraySelfidKey].stringValue
        recipients = json[kOrderDetailsArrayRecipientsKey].stringValue
        agid = json[kOrderDetailsArrayAgidKey].stringValue
        psvalue2 = json[kOrderDetailsArrayPsvalue2Key].stringValue
        pdtype = json[kOrderDetailsArrayPdtypeKey].stringValue
        orderamount = json[kOrderDetailsArrayOrderamountKey].floatValue
        bdname = json[kOrderDetailsArrayBdnameKey].stringValue
        
    }
    
    
    /**
     Generates description of the object in the form of a NSDictionary.
     - returns: A Key value pair containing all valid values in the object.
     */
    internal func dictionaryRepresentation() -> [String : AnyObject ] {
        
        var dictionary: [String : AnyObject ] = [ : ]
        
        dictionary.updateValue(invoiceflag as AnyObject, forKey: kOrderDetailsArrayInvoiceflagKey)
    
        dictionary.updateValue(pdid as AnyObject, forKey: kOrderDetailsArrayPdidKey)
    
        dictionary.updateValue(psfname as AnyObject, forKey: kOrderDetailsArrayPsfnameKey)
    
        dictionary.updateValue(payid as AnyObject, forKey: kOrderDetailsArrayPayidKey)
    
        dictionary.updateValue(adress as AnyObject, forKey: kOrderDetailsArrayAdressKey)
    
        dictionary.updateValue(comment as AnyObject, forKey: kOrderDetailsArrayCommentKey)
    
        dictionary.updateValue(orderstatus as AnyObject, forKey: kOrderDetailsArrayOrderstatusKey)
    
        dictionary.updateValue(detailid as AnyObject, forKey: kOrderDetailsArrayDetailidKey)
   
        dictionary.updateValue(skuid as AnyObject, forKey: kOrderDetailsArraySkuidKey)
    
        dictionary.updateValue(img1 as AnyObject, forKey: kOrderDetailsArrayImg1Key)

        dictionary.updateValue(isshow as AnyObject, forKey: kOrderDetailsArrayIsshowKey)

        dictionary.updateValue(orderid as AnyObject, forKey: kOrderDetailsArrayOrderidKey)

        dictionary.updateValue(detailstatus as AnyObject, forKey: kOrderDetailsArrayDetailstatusKey)

        dictionary.updateValue(psfname2 as AnyObject, forKey: kOrderDetailsArrayPsfname2Key)

        dictionary.updateValue(brid as AnyObject, forKey: kOrderDetailsArrayBridKey)

        dictionary.updateValue(province as AnyObject, forKey: kOrderDetailsArrayProvinceKey)

        dictionary.updateValue(isinvoice as AnyObject, forKey: kOrderDetailsArrayIsinvoiceKey)

        dictionary.updateValue(sendtype as AnyObject, forKey: kOrderDetailsArraySendtypeKey)

        dictionary.updateValue(invoicetitle as AnyObject, forKey: kOrderDetailsArrayInvoicetitleKey)

        dictionary.updateValue(city as AnyObject, forKey: kOrderDetailsArrayCityKey)

        dictionary.updateValue(shprice as AnyObject, forKey: kOrderDetailsArrayShpriceKey)

        dictionary.updateValue(pdname as AnyObject, forKey: kOrderDetailsArrayPdnameKey)

        dictionary.updateValue(detailrnumber as AnyObject, forKey: kOrderDetailsArrayDetailrnumberKey)

        dictionary.updateValue(isevaluate as AnyObject, forKey: kOrderDetailsArrayIsevaluateKey)

        dictionary.updateValue(issale as AnyObject, forKey: kOrderDetailsArrayIssaleKey)

        dictionary.updateValue(underdate as AnyObject, forKey: kOrderDetailsArrayUnderdateKey)

        dictionary.updateValue(bdid as AnyObject, forKey: kOrderDetailsArrayBdidKey)

        dictionary.updateValue(spid as AnyObject, forKey: kOrderDetailsArraySpidKey)

        dictionary.updateValue(area as AnyObject, forKey: kOrderDetailsArrayAreaKey)

        dictionary.updateValue(cellphone as AnyObject, forKey: kOrderDetailsArrayCellphoneKey)

        dictionary.updateValue(psvalue as AnyObject, forKey: kOrderDetailsArrayPsvalueKey)

        dictionary.updateValue(invoiceplace as AnyObject, forKey: kOrderDetailsArrayInvoiceplaceKey)

        dictionary.updateValue(detaildate as AnyObject, forKey: kOrderDetailsArrayDetaildateKey)

        dictionary.updateValue(detailtotal as AnyObject, forKey: kOrderDetailsArrayDetailtotalKey)

        dictionary.updateValue(postage as AnyObject, forKey: kOrderDetailsArrayPostageKey)

        dictionary.updateValue(selfid as AnyObject, forKey: kOrderDetailsArraySelfidKey)

        dictionary.updateValue(recipients as AnyObject, forKey: kOrderDetailsArrayRecipientsKey)

        dictionary.updateValue(agid as AnyObject, forKey: kOrderDetailsArrayAgidKey)

        dictionary.updateValue(psvalue2 as AnyObject, forKey: kOrderDetailsArrayPsvalue2Key)

        dictionary.updateValue(pdtype as AnyObject, forKey: kOrderDetailsArrayPdtypeKey)

        dictionary.updateValue(orderamount as AnyObject, forKey: kOrderDetailsArrayOrderamountKey)

        dictionary.updateValue(bdname as AnyObject, forKey: kOrderDetailsArrayBdnameKey)
    
        
        return dictionary
    }
    
    
}
